<template>
  <div>
    <header class="site-header jumbotron">
      <div class="container">
        <div class="row">
          <div class="col-xs-12">
            <h1>请发表对React的评论</h1>
          </div>
        </div>
      </div>
    </header>
    <div class="container">
      <AddComment :addComments="addComments"/>
      <ShowComment :commentData="commentData" :delComments="delComments"/>
    </div>
  </div>
</template>

<script>
  import AddComment from "./components/AddComment";
  import ShowComment from "./components/ShowComment";
  
  export default {
    name: "App",
    components: {ShowComment, AddComment},
    comments: {
      AddComment,
      ShowComment
    },
    data() {
      return {
        commentData: [
          {id: 1, username: 'xiaoyu', content: 'react easy'},
          {id: 2, username: 'yutian', content: ' good'},
          {id: 3, username: 'qingtian', content: 'say hello'},
        ]
      }
    },
    methods: {
      addComments(username, content) {
        this.commentData.unshift({
          id: Date.now(),
          username,
          content
        })
      },
      delComments(id) {
        const newCommentData = this.commentData.filter(item =>
             item.id !== id
        )
        this.commentData = newCommentData
        console.log(this.commentData)
      }
      
    }
  }
</script>

<style scoped>

</style>